#ifndef MTALOG_H_
#define MTALOG_H_
#include <f32file.h>

const TInt KMaxLogEntrySize = 1024;
#define ENABLELOG
#ifdef ENABLELOG

#define LOGCLOSE            CFileLogger::Close()
#define LOGARG(txt,parm...) {_LIT8(KTxt, txt); CFileLogger::Write(KTxt, parm);}
#define LOGTXT(txt)         {_LIT8(KTxt, txt); CFileLogger::Write((const TDesC8&)KTxt);}
#define LOGDES8(des)        CFileLogger::Write((const TDesC8&)des);
#define LOGDES16(des)       CFileLogger::Write(des);
#define LOGERR(txt,err)     if (err) LOGARG(txt, err)
#define LOGCALL(exp)        {LOGARG("Calling \"%s\"", #exp); exp; LOGARG("Call to \"%s\" passed.", #exp);}
#define LOGENTER            LOGARG("%s start", __PRETTY_FUNCTION__)
#define LOGEXIT             LOGARG("%s end", __PRETTY_FUNCTION__)
#define LOGMEM(ptr)         LOGARG("%s [0x%x]", #ptr, (TUint)ptr)

#else

#define LOGCLOSE            {}
#define LOGARG(txt,parm...) {}
#define LOGTXT(txt)         {}
#define LOGDES8(des)        {}
#define LOGDES16(des)       {}
#define LOGERR(txt,err)     {}
#define LOGCALL(exp)        {}
#define LOGENTER            {}
#define LOGEXIT             {}
#define LOGMEM(ptr)         {}

#endif

 
class CFileLogger : public CBase
{
public:
	IMPORT_C static void Write(const TDesC8& aText);
	IMPORT_C static void Write(const TDesC16& aText);
	IMPORT_C static void Write(TRefByValue<const TDesC8> aFmt,...);
	IMPORT_C static void Close();
 
private:
	CFileLogger();
	~CFileLogger();
	TBool Construct();
	static CFileLogger* Logger();
	void DoWrite();
	TBool GetLogFileNameWithoutExt(TDes& aFileName);
 
private:
	RFs                     iFs;
	RFile                   iFile;
	TBuf8<KMaxLogEntrySize> iLogBuffer;
	static CFileLogger* iLogger;
};
 
#endif /*MTALOG_H_*/
